<!DOCTYPE html>
<html lang="en">
  <head>
    <title>Restofire  Reference</title>
    <link rel="stylesheet" type="text/css" href="css/jazzy.css" />
    <link rel="stylesheet" type="text/css" href="css/highlight.css" />
    <meta charset='utf-8'>
    <script src="js/jquery.min.js" defer></script>
    <script src="js/jazzy.js" defer></script>
    
  </head>
  <body>
    <a title="Restofire  Reference"></a>
    <header>
      <div class="content-wrapper">
        <p><a href="index.html">Restofire Docs</a> (85% documented)</p>
      </div>
    </header>
    <div class="content-wrapper">
      <p id="breadcrumbs">
        <a href="index.html">Restofire Reference</a>
        <img id="carat" src="img/carat.png" />
        Restofire  Reference
      </p>
    </div>
    <div class="content-wrapper">
      <nav class="sidebar">
        <ul class="nav-groups">
          <li class="nav-group-name">
            <a href="Classes.html">Classes</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="Classes/AnyResponseSerializer.html">AnyResponseSerializer</a>
              </li>
              <li class="nav-group-task">
                <a href="Classes/DownloadOperation.html">DownloadOperation</a>
              </li>
              <li class="nav-group-task">
                <a href="Classes/NetworkOperation.html">NetworkOperation</a>
              </li>
              <li class="nav-group-task">
                <a href="Classes/RequestOperation.html">RequestOperation</a>
              </li>
              <li class="nav-group-task">
                <a href="Classes/UploadOperation.html">UploadOperation</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a href="Enums.html">Enumerations</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="Enums/ParametersType.html">ParametersType</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a href="Extensions.html">Extensions</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="Extensions/JSONEncoding.html">JSONEncoding</a>
              </li>
              <li class="nav-group-task">
                <a href="Extensions/Result.html">Result</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a href="Protocols.html">Protocols</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="Protocols/ArrayParameterEncoding.html">ArrayParameterEncoding</a>
              </li>
              <li class="nav-group-task">
                <a href="Protocols/Authenticable.html">Authenticable</a>
              </li>
              <li class="nav-group-task">
                <a href="Protocols/BackgroundQosable.html">BackgroundQosable</a>
              </li>
              <li class="nav-group-task">
                <a href="Protocols/BaseRequestable.html">BaseRequestable</a>
              </li>
              <li class="nav-group-task">
                <a href="Protocols/Cancellable.html">Cancellable</a>
              </li>
              <li class="nav-group-task">
                <a href="Protocols/Configurable.html">Configurable</a>
              </li>
              <li class="nav-group-task">
                <a href="Protocols/CoreDataSyncable.html">CoreDataSyncable</a>
              </li>
              <li class="nav-group-task">
                <a href="Protocols/DataUploadable.html">DataUploadable</a>
              </li>
              <li class="nav-group-task">
                <a href="Protocols/DefaultQosable.html">DefaultQosable</a>
              </li>
              <li class="nav-group-task">
                <a href="Protocols/Downloadable.html">Downloadable</a>
              </li>
              <li class="nav-group-task">
                <a href="Protocols/FileUploadable.html">FileUploadable</a>
              </li>
              <li class="nav-group-task">
                <a href="Protocols/HighQueuePriortizable.html">HighQueuePriortizable</a>
              </li>
              <li class="nav-group-task">
                <a href="Protocols/LowQueuePriortizable.html">LowQueuePriortizable</a>
              </li>
              <li class="nav-group-task">
                <a href="Protocols/MultipartUploadable.html">MultipartUploadable</a>
              </li>
              <li class="nav-group-task">
                <a href="Protocols/NormalQueuePriortizable.html">NormalQueuePriortizable</a>
              </li>
              <li class="nav-group-task">
                <a href="Protocols/Pollable.html">Pollable</a>
              </li>
              <li class="nav-group-task">
                <a href="Protocols/Qosable.html">Qosable</a>
              </li>
              <li class="nav-group-task">
                <a href="Protocols/QueuePriortizable.html">QueuePriortizable</a>
              </li>
              <li class="nav-group-task">
                <a href="Protocols/Queueable.html">Queueable</a>
              </li>
              <li class="nav-group-task">
                <a href="Protocols/Reachable.html">Reachable</a>
              </li>
              <li class="nav-group-task">
                <a href="Protocols/RequestDelegate.html">RequestDelegate</a>
              </li>
              <li class="nav-group-task">
                <a href="Protocols/Requestable.html">Requestable</a>
              </li>
              <li class="nav-group-task">
                <a href="Protocols/ResponseSerializable.html">ResponseSerializable</a>
              </li>
              <li class="nav-group-task">
                <a href="Protocols/Retryable.html">Retryable</a>
              </li>
              <li class="nav-group-task">
                <a href="Protocols/SessionManagable.html">SessionManagable</a>
              </li>
              <li class="nav-group-task">
                <a href="Protocols/StreamUploadable.html">StreamUploadable</a>
              </li>
              <li class="nav-group-task">
                <a href="Protocols/Syncable.html">Syncable</a>
              </li>
              <li class="nav-group-task">
                <a href="Protocols/Uploadable.html">Uploadable</a>
              </li>
              <li class="nav-group-task">
                <a href="Protocols/UserInitiatedQosable.html">UserInitiatedQosable</a>
              </li>
              <li class="nav-group-task">
                <a href="Protocols/UserInteractiveQosable.html">UserInteractiveQosable</a>
              </li>
              <li class="nav-group-task">
                <a href="Protocols/UtilityQosable.html">UtilityQosable</a>
              </li>
              <li class="nav-group-task">
                <a href="Protocols/Validatable.html">Validatable</a>
              </li>
              <li class="nav-group-task">
                <a href="Protocols/VeryHighQueuePriortizable.html">VeryHighQueuePriortizable</a>
              </li>
              <li class="nav-group-task">
                <a href="Protocols/VeryLowQueuePriortizable.html">VeryLowQueuePriortizable</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a href="Structs.html">Structures</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="Structs/Authentication.html">Authentication</a>
              </li>
              <li class="nav-group-task">
                <a href="Structs/Configuration.html">Configuration</a>
              </li>
              <li class="nav-group-task">
                <a href="Structs/Poll.html">Poll</a>
              </li>
              <li class="nav-group-task">
                <a href="Structs/Queues.html">Queues</a>
              </li>
              <li class="nav-group-task">
                <a href="Structs/Reachability.html">Reachability</a>
              </li>
              <li class="nav-group-task">
                <a href="Structs/Retry.html">Retry</a>
              </li>
              <li class="nav-group-task">
                <a href="Structs/SessionManager.html">SessionManager</a>
              </li>
              <li class="nav-group-task">
                <a href="Structs/Validation.html">Validation</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a href="Typealiases.html">Type Aliases</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="Typealiases.html#/s:9Restofire11DataRequesta">DataRequest</a>
              </li>
              <li class="nav-group-task">
                <a href="Typealiases.html#/s:9Restofire12DataResponsea">DataResponse</a>
              </li>
              <li class="nav-group-task">
                <a href="Typealiases.html#/s:9Restofire22DataResponseSerializera">DataResponseSerializer</a>
              </li>
              <li class="nav-group-task">
                <a href="Typealiases.html#/s:9Restofire15DownloadRequesta">DownloadRequest</a>
              </li>
              <li class="nav-group-task">
                <a href="Typealiases.html#/s:9Restofire16DownloadResponsea">DownloadResponse</a>
              </li>
              <li class="nav-group-task">
                <a href="Typealiases.html#/s:9Restofire10HTTPHeadera">HTTPHeader</a>
              </li>
              <li class="nav-group-task">
                <a href="Typealiases.html#/s:9Restofire11HTTPHeadersa">HTTPHeaders</a>
              </li>
              <li class="nav-group-task">
                <a href="Typealiases.html#/s:9Restofire10HTTPMethoda">HTTPMethod</a>
              </li>
              <li class="nav-group-task">
                <a href="Typealiases.html#/s:9Restofire12JSONEncodinga">JSONEncoding</a>
              </li>
              <li class="nav-group-task">
                <a href="Typealiases.html#/s:9Restofire20JSONParameterEncodera">JSONParameterEncoder</a>
              </li>
              <li class="nav-group-task">
                <a href="Typealiases.html#/s:9Restofire17MultipartFormDataa">MultipartFormData</a>
              </li>
              <li class="nav-group-task">
                <a href="Typealiases.html#/s:9Restofire26NetworkReachabilityManagera">NetworkReachabilityManager</a>
              </li>
              <li class="nav-group-task">
                <a href="Typealiases.html#/s:9Restofire16ParameterEncodera">ParameterEncoder</a>
              </li>
              <li class="nav-group-task">
                <a href="Typealiases.html#/s:9Restofire17ParameterEncodinga">ParameterEncoding</a>
              </li>
              <li class="nav-group-task">
                <a href="Typealiases.html#/s:9Restofire7RFErrora">RFError</a>
              </li>
              <li class="nav-group-task">
                <a href="Typealiases.html#/s:9Restofire8RFResulta">RFResult</a>
              </li>
              <li class="nav-group-task">
                <a href="Typealiases.html#/s:9Restofire7Requesta">Request</a>
              </li>
              <li class="nav-group-task">
                <a href="Typealiases.html#/s:9Restofire7Sessiona">Session</a>
              </li>
              <li class="nav-group-task">
                <a href="Typealiases.html#/s:9Restofire30URLEncodedFormParameterEncodera">URLEncodedFormParameterEncoder</a>
              </li>
              <li class="nav-group-task">
                <a href="Typealiases.html#/s:9Restofire11URLEncodinga">URLEncoding</a>
              </li>
              <li class="nav-group-task">
                <a href="Typealiases.html#/s:9Restofire21URLRequestConvertiblea">URLRequestConvertible</a>
              </li>
              <li class="nav-group-task">
                <a href="Typealiases.html#/s:9Restofire13UploadRequesta">UploadRequest</a>
              </li>
            </ul>
          </li>
        </ul>
      </nav>
      <article class="main-content">
        <section>
          <section class="section">
            
            <h2 id='img-src-https-raw-githubusercontent-com-restofire-restofire-master-assets-restofire-png-alt-restofire-a-protocol-oriented-networking-abstraction-layer-in-swift' class='heading'><img src="https://raw.githubusercontent.com/Restofire/Restofire/master/Assets/restofire.png" alt="Restofire: A Protocol Oriented Networking Abstraction Layer in Swift"></h2>

<p><a href="https://cocoapods.org/pods/Restofire"><img src="https://img.shields.io/cocoapods/p/Restofire.svg" alt="Platforms"></a>
<a href="https://raw.githubusercontent.com/Restofire/Restofire/master/LICENSE"><img src="https://img.shields.io/cocoapods/l/Restofire.svg" alt="License"></a></p>

<p><a href="https://github.com/apple/swift-package-manager"><img src="https://img.shields.io/badge/Swift%20Package%20Manager-compatible-brightgreen.svg" alt="Swift Package Manager"></a>
<a href="https://github.com/Carthage/Carthage"><img src="https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat" alt="Carthage compatible"></a>
<a href="https://cocoapods.org/pods/Restofire"><img src="https://img.shields.io/cocoapods/v/Restofire.svg" alt="CocoaPods compatible"></a></p>

<p><a href="https://travis-ci.org/Restofire/Restofire/branches"><img src="https://img.shields.io/travis/Restofire/Restofire/master.svg" alt="Travis"></a></p>

<p><a href="https://gitter.im/Restofire/Restofire?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge"><img src="https://badges.gitter.im/Restofire/Restofire.svg" alt="Join the chat at https://gitter.im/Restofire/Restofire"></a>
<a href="https://twitter.com/rahulkatariya91"><img src="https://img.shields.io/twitter/follow/rahulkatariya91.svg?style=social&label=Follow" alt="Twitter"></a></p>

<p>Restofire is a protocol oriented networking client for <a href="https://github.com/Alamofire/Alamofire">Alamofire</a>.</p>

<ul>
<li><a href="#features">Features</a></li>
<li><a href="#requirements">Requirements</a></li>
<li><a href="#installation">Installation</a></li>
<li><a href="#usage">Usage</a></li>
<li><a href="#license">License</a></li>
</ul>
<h2 id='features' class='heading'>Features</h2>

<ul>
<li>[x] Global Configuration for host / headers / parameters etc</li>
<li>[x] Group Configurations</li>
<li>[x] Per Request Configuration</li>
<li>[x] Authentication</li>
<li>[x] Response Validations</li>
<li>[x] Custom Response Serializers like JSONDecodable</li>
<li>[x] Isolate Network Requests from ViewControllers</li>
<li>[x] Auto retry based on URLError codes</li>
<li>[x] Request eventually when network is reachable</li>
<li>[x] NSOperations</li>
<li>[x] <a href="http://restofire.github.io/Restofire/">Complete Documentation</a></li>
</ul>
<h2 id='requirements' class='heading'>Requirements</h2>

<ul>
<li>iOS 10.0+ / Mac OS X 10.12+ / tvOS 10.0+ / watchOS 3.0+</li>
<li>Xcode 10</li>
</ul>
<h2 id='installation' class='heading'>Installation</h2>
<h3 id='dependency-managers' class='heading'>Dependency Managers</h3>

<details>
  <summary><strong>CocoaPods</strong></summary>

[CocoaPods](http://cocoapods.org) is a dependency manager for Cocoa projects. You can install it with the following command:

&ldquo;`bash
$ gem install cocoapods
&rdquo;`

To integrate Restofire into your Xcode project using CocoaPods, specify it in your `Podfile`:

&ldquo;`ruby
source &lsquo;https://github.com/CocoaPods/Specs.git&rsquo;
platform :ios, &lsquo;10.0&rsquo;
use_frameworks!

pod &lsquo;Restofire&rsquo;, &lsquo;~> 5.0&rsquo;
&rdquo;`

Then, run the following command:

&ldquo;`bash
$ pod install
&rdquo;`

</details>

<details>
  <summary><strong>Carthage</strong></summary>

[Carthage](https://github.com/Carthage/Carthage) is a decentralized dependency manager that automates the process of adding frameworks to your Cocoa application.

You can install Carthage with [Homebrew](http://brew.sh/) using the following command:

&ldquo;`bash
$ brew update
$ brew install carthage
&rdquo;`

To integrate Restofire into your Xcode project using Carthage, specify it in your `Cartfile`:

&ldquo;`ogdl
github &quot;Restofire/Restofire&rdquo; ~> 5.0
&ldquo;`

</details>

<details>
  <summary><strong>Swift Package Manager</strong></summary>

To use Restofire as a [Swift Package Manager](https://swift.org/package-manager/) package just add the following in your Package.swift file.

&rdquo;`swift
import PackageDescription

let package = Package(
    name: &ldquo;HelloRestofire&rdquo;,
    dependencies: [
        .Package(url: &ldquo;https://github.com/Restofire/Restofire.git&rdquo;, from: &ldquo;5.0.0&rdquo;)
    ]
)
&ldquo;`

</details>
<h3 id='manually' class='heading'>Manually</h3>

<p>If you prefer not to use either of the aforementioned dependency managers, you can integrate Restofire into your project manually.</p>

<details>
  <summary><strong>Git Submodules</strong></summary><p>

- Open up Terminal, `cd` into your top-level project directory, and run the following command &quot;if&rdquo; your project is not initialized as a git repository:

&ldquo;`bash
$ git init
&rdquo;`

- Add Restofire as a git [submodule](http://git-scm.com/docs/git-submodule) by running the following command:

&ldquo;`bash
$ git submodule add https://github.com/Restofire/Restofire.git
$ git submodule update &ndash;init &ndash;recursive
&rdquo;`

- Open the new `Restofire` folder, and drag the `Restofire.xcodeproj` into the Project Navigator of your application&rsquo;s Xcode project.

  > It should appear nested underneath your application&rsquo;s blue project icon. Whether it is above or below all the other Xcode groups does not matter.

- Select the `Restofire.xcodeproj` in the Project Navigator and verify the deployment target matches that of your application target.
- Next, select your application project in the Project Navigator (blue project icon) to navigate to the target configuration window and select the application target under the &ldquo;Targets&rdquo; heading in the sidebar.
- In the tab bar at the top of that window, open the &ldquo;General&rdquo; panel.
- Click on the `+` button under the &ldquo;Embedded Binaries&rdquo; section.
- You will see two different `Restofire.xcodeproj` folders each with two different versions of the `Restofire.framework` nested inside a `Products` folder.

  > It does not matter which `Products` folder you choose from.

- Select the `Restofire.framework` & `Alamofire.framework`.

- And that&rsquo;s it!

> The `Restofire.framework` is automagically added as a target dependency, linked framework and embedded framework in a copy files build phase which is all you need to build on the simulator and a device.

</p></details>

<details>
  <summary><strong>Embeded Binaries</strong></summary><p>

- Download the latest release from https://github.com/Restofire/Restofire/releases
- Next, select your application project in the Project Navigator (blue project icon) to navigate to the target configuration window and select the application target under the &ldquo;Targets&rdquo; heading in the sidebar.
- In the tab bar at the top of that window, open the &ldquo;General&rdquo; panel.
- Click on the `+` button under the &ldquo;Embedded Binaries&rdquo; section.
- Add the downloaded `Restofire.framework` & `Alamofire.framework`.
- And that&rsquo;s it!

</p></details>
<h3 id='configurations' class='heading'>Configurations</h3>
<h4 id='three-levels-of-configuration' class='heading'>Three levels of configuration</h4>

<ul>
<li><strong>Global Configuration</strong> – The global configuration will be applied to all the requests. These include values like scheme, host, version, headers, sessionManager, callbackQueue, maxRetryCount, waitsForConnectivity etc.</li>
</ul>
<pre class="highlight swift"><code><span class="kd">func</span> <span class="nf">application</span><span class="p">(</span><span class="nv">application</span><span class="p">:</span> <span class="kt">UIApplication</span><span class="p">,</span> <span class="n">didFinishLaunchingWithOptions</span> <span class="nv">launchOptions</span><span class="p">:</span> <span class="p">[</span><span class="kt">NSObject</span><span class="p">:</span> <span class="kt">AnyObject</span><span class="p">]?)</span> <span class="o">-&gt;</span> <span class="kt">Bool</span> <span class="p">{</span>

    <span class="kt">Restofire</span><span class="o">.</span><span class="kt">Configuration</span><span class="o">.</span><span class="k">default</span><span class="o">.</span><span class="n">host</span> <span class="o">=</span> <span class="s">"httpbin.org"</span>
    <span class="kt">Restofire</span><span class="o">.</span><span class="kt">Retry</span><span class="o">.</span><span class="k">default</span><span class="o">.</span><span class="n">retryErrorCodes</span> <span class="o">=</span> <span class="p">[</span><span class="o">.</span><span class="n">requestTimedOut</span><span class="p">,</span><span class="o">.</span><span class="n">networkConnectionLost</span><span class="p">]</span>

    <span class="k">return</span> <span class="kc">true</span>
<span class="p">}</span>
</code></pre>

<ul>
<li><strong>Group Configuration</strong> – The group configuration inherits all the values from the global configuration. It can be used to group requests that have same behaviour but are different from the global configuration. For instance, If you have more than one host or if your global configuration has default url session and some requests require you to use ephemeral URL session.</li>
</ul>
<pre class="highlight swift"><code><span class="kd">import</span> <span class="kt">Restofire</span>

<span class="kd">protocol</span> <span class="kt">ApiaryConfigurable</span><span class="p">:</span> <span class="kt">Configurable</span> <span class="p">{}</span>

<span class="kd">extension</span> <span class="kt">ApiaryConfigurable</span> <span class="p">{</span>
    <span class="kd">public</span> <span class="k">var</span> <span class="nv">configuration</span><span class="p">:</span> <span class="kt">Configuration</span> <span class="p">{</span>
        <span class="k">var</span> <span class="nv">configuration</span> <span class="o">=</span> <span class="kt">Configuration</span><span class="o">.</span><span class="k">default</span>
        <span class="n">configuration</span><span class="o">.</span><span class="n">host</span> <span class="o">=</span> <span class="s">"private-07c21-rahulkatariya.apiary-mock.com"</span>
        <span class="n">configuration</span><span class="o">.</span><span class="n">headers</span> <span class="o">=</span> <span class="p">[</span><span class="s">"Content-Type"</span><span class="p">:</span> <span class="s">"application/json"</span><span class="p">]</span>
        <span class="k">return</span> <span class="n">configuration</span>
    <span class="p">}</span>
<span class="p">}</span>

<span class="kd">protocol</span> <span class="kt">ApiaryRequestable</span><span class="p">:</span> <span class="kt">Requestable</span><span class="p">,</span> <span class="kt">ApiaryConfigurable</span> <span class="p">{}</span>

<span class="kd">import</span> <span class="kt">Restofire</span>

<span class="kd">struct</span> <span class="kt">NoteResponseModel</span><span class="p">:</span> <span class="kt">Decodable</span> <span class="p">{</span>
    <span class="k">var</span> <span class="nv">id</span><span class="p">:</span> <span class="kt">Int16</span>
    <span class="k">var</span> <span class="nv">title</span><span class="p">:</span> <span class="kt">String</span>
<span class="p">}</span>

<span class="kd">struct</span> <span class="kt">NotesGETService</span><span class="p">:</span> <span class="kt">ApiaryRequestable</span> <span class="p">{</span>
    <span class="kd">typealias</span> <span class="kt">Response</span> <span class="o">=</span> <span class="p">[</span><span class="kt">NoteResponseModel</span><span class="p">]</span>
    <span class="k">var</span> <span class="nv">path</span><span class="p">:</span> <span class="kt">String</span><span class="p">?</span> <span class="o">=</span> <span class="s">"notes"</span>
<span class="p">}</span>
</code></pre>

<ul>
<li><strong>Per Request Configuration</strong> – The request configuration inherits all the values from the group configuration or directly from the global configuration.</li>
</ul>
<pre class="highlight swift"><code><span class="kd">import</span> <span class="kt">Restofire</span>

<span class="kd">struct</span> <span class="kt">NoteRequestModel</span><span class="p">:</span> <span class="kt">Encodable</span> <span class="p">{</span>
    <span class="k">var</span> <span class="nv">title</span><span class="p">:</span> <span class="kt">String</span>
<span class="p">}</span>

<span class="kd">struct</span> <span class="kt">NotePOSTService</span><span class="p">:</span> <span class="kt">Requestable</span> <span class="p">{</span>
    <span class="kd">typealias</span> <span class="kt">Response</span> <span class="o">=</span> <span class="kt">NoteResponseModel</span>
    <span class="k">let</span> <span class="nv">host</span><span class="p">:</span> <span class="kt">String</span> <span class="o">=</span> <span class="s">"private-07c21-rahulkatariya.apiary-mock.com"</span>
    <span class="k">let</span> <span class="nv">headers</span> <span class="o">=</span> <span class="p">[</span><span class="s">"Content-Type"</span><span class="p">:</span> <span class="s">"application/json"</span><span class="p">]</span>
    <span class="k">let</span> <span class="nv">path</span><span class="p">:</span> <span class="kt">String</span><span class="p">?</span> <span class="o">=</span> <span class="s">"notes"</span>
    <span class="k">let</span> <span class="nv">method</span><span class="p">:</span> <span class="kt">HTTPMethod</span> <span class="o">=</span> <span class="o">.</span><span class="n">post</span>
    <span class="k">var</span> <span class="nv">parameters</span><span class="p">:</span> <span class="kt">Any</span><span class="p">?</span>

    <span class="nf">init</span><span class="p">(</span><span class="nv">parameters</span><span class="p">:</span> <span class="kt">NoteRequestModel</span><span class="p">)</span> <span class="p">{</span>
        <span class="k">let</span> <span class="nv">data</span> <span class="o">=</span> <span class="k">try!</span> <span class="kt">JSONEncoder</span><span class="p">()</span><span class="o">.</span><span class="nf">encode</span><span class="p">(</span><span class="n">parameters</span><span class="p">)</span>
        <span class="k">self</span><span class="o">.</span><span class="n">parameters</span> <span class="o">=</span> <span class="k">try!</span> <span class="kt">JSONSerialization</span><span class="o">.</span><span class="nf">jsonObject</span><span class="p">(</span><span class="nv">with</span><span class="p">:</span> <span class="n">data</span><span class="p">,</span> <span class="nv">options</span><span class="p">:</span> <span class="o">.</span><span class="n">allowFragments</span><span class="p">)</span>
    <span class="p">}</span>
<span class="p">}</span>
</code></pre>
<h2 id='usage' class='heading'>Usage</h2>
<h3 id='making-a-request' class='heading'>Making a Request</h3>

<p><code><a href="Protocols/Requestable.html">Requestable</a></code> gives completion handler to enable making requests and receive response.</p>
<pre class="highlight swift"><code><span class="kd">import</span> <span class="kt">Restofire</span>

<span class="kd">class</span> <span class="kt">ViewController</span><span class="p">:</span> <span class="kt">UITableViewController</span> <span class="p">{</span>
    <span class="k">var</span> <span class="nv">notes</span><span class="p">:</span> <span class="p">[</span><span class="kt">NoteResponseModel</span><span class="p">]</span><span class="o">!</span>
    <span class="k">var</span> <span class="nv">requestOp</span><span class="p">:</span> <span class="kt">RequestOperation</span><span class="o">&lt;</span><span class="kt">NotesGetAllService</span><span class="o">&gt;!</span>

    <span class="k">override</span> <span class="kd">func</span> <span class="nf">viewDidLoad</span><span class="p">()</span> <span class="p">{</span>
        <span class="k">super</span><span class="o">.</span><span class="nf">viewDidLoad</span><span class="p">()</span>
        <span class="c1">// We want to cancel the request to save resources when the user pops the view controller.</span>
        <span class="n">requestOp</span> <span class="o">=</span> <span class="kt">NotesGetAllService</span><span class="p">()</span><span class="o">.</span><span class="nf">execute</span><span class="p">()</span> <span class="p">{</span>
            <span class="k">if</span> <span class="k">let</span> <span class="nv">value</span> <span class="o">=</span> <span class="nv">$0</span><span class="o">.</span><span class="n">result</span><span class="o">.</span><span class="n">value</span> <span class="p">{</span>
                <span class="k">self</span><span class="o">.</span><span class="n">notes</span> <span class="o">=</span> <span class="n">value</span>
            <span class="p">}</span>
        <span class="p">}</span>
    <span class="p">}</span>

    <span class="kd">func</span> <span class="nf">postNote</span><span class="p">(</span><span class="nv">title</span><span class="p">:</span> <span class="kt">String</span><span class="p">)</span> <span class="p">{</span>
        <span class="k">let</span> <span class="nv">noteRequestModel</span> <span class="o">=</span> <span class="kt">NoteRequestModel</span><span class="p">(</span><span class="nv">title</span><span class="p">:</span> <span class="n">title</span><span class="p">)</span>
        <span class="c1">// We don't want to cancel the request even if user pops the view controller.</span>
        <span class="kt">NotePOSTService</span><span class="p">(</span><span class="nv">parameters</span><span class="p">:</span> <span class="n">noteRequestModel</span><span class="p">)</span><span class="o">.</span><span class="nf">execute</span><span class="p">()</span>
    <span class="p">}</span>

    <span class="kd">deinit</span> <span class="p">{</span>
        <span class="n">requestOp</span><span class="o">.</span><span class="nf">cancel</span><span class="p">()</span>
    <span class="p">}</span>
<span class="p">}</span>
</code></pre>
<h3 id='isolating-network-requests-from-uiviewcontrollers' class='heading'>Isolating Network Requests from UIViewControllers</h3>

<p><code><a href="Protocols/Requestable.html">Requestable</a></code> gives delegate methods to enable making requests from anywhere which you can use to store data in your cache.</p>
<pre class="highlight swift"><code><span class="kd">import</span> <span class="kt">Restofire</span>

<span class="kd">struct</span> <span class="kt">NotesGetAllService</span><span class="p">:</span> <span class="kt">ApiaryRequestable</span> <span class="p">{</span>
    <span class="o">...</span>

    <span class="kd">func</span> <span class="nf">request</span><span class="p">(</span><span class="n">_</span> <span class="nv">request</span><span class="p">:</span> <span class="kt">RequestOperation</span><span class="o">&lt;</span><span class="kt">NotesGetAllService</span><span class="o">&gt;</span><span class="p">,</span> <span class="n">didCompleteWithValue</span> <span class="nv">value</span><span class="p">:</span> <span class="p">[</span><span class="kt">NoteResponseModel</span><span class="p">])</span> <span class="p">{</span>
      <span class="c1">// Here you can store the results into your cache and then listen for changes inside your view controller.</span>
    <span class="p">}</span>
<span class="p">}</span>
</code></pre>
<h3 id='custom-response-serializers' class='heading'>Custom Response Serializers</h3>

<ul>
<li><strong>Decodable</strong></li>
</ul>

<p>By adding the following snippet in your project, All <code><a href="Protocols/Requestable.html">Requestable</a></code> associatedType Response as <code>Decodable</code> will be decoded with JSONDecoder.</p>
<pre class="highlight swift"><code><span class="kd">import</span> <span class="kt">Restofire</span>

<span class="kd">extension</span> <span class="kt">Restofire</span><span class="o">.</span><span class="kt">DataResponseSerializable</span> <span class="k">where</span> <span class="kt">Response</span><span class="p">:</span> <span class="kt">Decodable</span> <span class="p">{</span>
    <span class="kd">public</span> <span class="k">var</span> <span class="nv">responseSerializer</span><span class="p">:</span> <span class="kt">DataResponseSerializer</span><span class="o">&lt;</span><span class="kt">Response</span><span class="o">&gt;</span> <span class="p">{</span>
        <span class="k">return</span> <span class="kt">DataRequest</span><span class="o">.</span><span class="kt">JSONDecodableResponseSerializer</span><span class="p">()</span>
    <span class="p">}</span>
<span class="p">}</span>
</code></pre>

<ul>
<li><strong>JSON</strong></li>
</ul>

<p>By adding the following snippet in your project, All <code><a href="Protocols/Requestable.html">Requestable</a></code> associatedType Response as <code>Any</code> will be decoded with NSJSONSerialization.</p>
<pre class="highlight swift"><code><span class="kd">import</span> <span class="kt">Restofire</span>

<span class="kd">extension</span> <span class="kt">Restofire</span><span class="o">.</span><span class="kt">DataResponseSerializable</span> <span class="k">where</span> <span class="kt">Response</span> <span class="o">==</span> <span class="kt">Any</span> <span class="p">{</span>
    <span class="kd">public</span> <span class="k">var</span> <span class="nv">responseSerializer</span><span class="p">:</span> <span class="kt">DataResponseSerializer</span><span class="o">&lt;</span><span class="kt">Response</span><span class="o">&gt;</span> <span class="p">{</span>
        <span class="k">return</span> <span class="kt">DataRequest</span><span class="o">.</span><span class="nf">jsonResponseSerializer</span><span class="p">()</span>
    <span class="p">}</span>
<span class="p">}</span>
</code></pre>
<h3 id='wait-for-internet-connectivity' class='heading'>Wait for Internet Connectivity</h3>

<p><code><a href="Protocols/Requestable.html">Requestable</a></code> gives you a property waitsForConnectivity which can be set to true. This will make the first request regardless of the internet connectivity. If the request fails due to .notConnectedToInternet, it will retry the request when internet connection is established.</p>
<pre class="highlight swift"><code><span class="kd">struct</span> <span class="kt">PushTokenPutService</span><span class="p">:</span> <span class="kt">Requestable</span> <span class="p">{</span>

    <span class="kd">typealias</span> <span class="kt">Response</span> <span class="o">=</span> <span class="kt">Data</span>
    <span class="o">...</span>
    <span class="k">var</span> <span class="nv">waitsForConnectivity</span><span class="p">:</span> <span class="kt">Bool</span> <span class="o">=</span> <span class="kc">true</span>

<span class="p">}</span>
</code></pre>
<h1 id='contributing' class='heading'>Contributing</h1>

<p>Issues and pull requests are welcome!</p>
<h1 id='author' class='heading'>Author</h1>

<p>Rahul Katariya <a href="https://twitter.com/rahulkatariya91">@rahulkatariya91</a></p>
<h2 id='license' class='heading'>License</h2>

<p>Restofire is released under the MIT license. See <a href="https://github.com/Restofire/Restofire/blob/master/LICENSE">LICENSE</a> for details.</p>

          </section>
        </section>
        <section id="footer">
          <p>&copy; 2020 <a class="link" href="https://github.com/Restofire/Restofire" target="_blank" rel="external">Rahul Katariya</a>. All rights reserved. (Last updated: 2020-02-19)</p>
          <p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.13.1</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
        </section>
      </article>
    </div>
  </body>
</div>
</html>
